package com.xgk.boot.module.core.service.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.framework.common.util.object.BeanUtils;
import com.xgk.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xgk.boot.module.core.controller.order.vo.OrderReqVo;
import com.xgk.boot.module.core.controller.order.vo.OrdersVO;
import com.xgk.boot.module.core.dal.entity.order.OrdersDO;
import com.xgk.boot.module.core.dal.mapper.order.OrdersMapper;
import com.xgk.boot.module.core.dal.iservice.order.OrdersService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单信息主表 服务实现类
 * </p>
 *
 * @author yfbao
 * @since 2025-06-14
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersDO> implements OrdersService {


    //根据条件进行分页查询
    public PageResult<OrdersVO> pageList(OrderReqVo reqVo) {
        LambdaQueryWrapperX<OrdersDO> ordersDOLambdaQueryWrapperX = new LambdaQueryWrapperX<OrdersDO>()
                //订单code
                .eqIfPresent(OrdersDO::getOrderCode, reqVo.getOrderCode())
                //订单状态
                .inIfPresent(OrdersDO::getOrderStatus, reqVo.getOrderStatusList())
                //订单类型
                .eqIfPresent(OrdersDO::getOrderType, reqVo.getOrderType())
                //客户编码
                .eqIfPresent(OrdersDO::getCustomerCode, reqVo.getCustomerCode())
                //参考号
                .eqIfPresent(OrdersDO::getReferenceNo, reqVo.getReferenceNo())
                //运单号
                .likeIfPresent(OrdersDO::getTrackingNumber, reqVo.getTrackingNumber())
                //物流产品代码
                .likeIfPresent(OrdersDO::getSmCode, reqVo.getSmCode())
                //服务商渠道代码
                .likeIfPresent(OrdersDO::getSpCode, reqVo.getSpCode());
        Page<OrdersDO> page = new Page<>(reqVo.getCurrent(), reqVo.getPageSize());
        Page<OrdersDO> pageRes = this.page(page, ordersDOLambdaQueryWrapperX);
        List<OrdersVO> bean = BeanUtils.toBean(pageRes.getRecords(), OrdersVO.class);
        return new PageResult<>(bean, pageRes.getTotal(), reqVo.getCurrent(), reqVo.getPageSize());
    }


}
